import Dialog from '../../../miniprogram_npm/vant-weapp/dialog/dialog';
import { UserModel} from "../../../models/user.js";
var user = new UserModel();
var _self
Page({
  data: {
      summary:"",
      items: [],
      userTag:[]
  },
  onLoad: function (options) {
    
    _self = this;
    if(options.summary!=""){
      _self.setData({
        summary:options.summary
      })
    }
    user.getLabel(function(data){
         if(options.label!=""){
           let labelArray = options.label.split(",");
           _self.setData({
             userTag: labelArray
           })
           for(let i=0;i<labelArray.length;i++){
             data.forEach(function(item,index){
               if(labelArray[i]==item.labelName){
                  item.checked=true
               }
             })
           }
         }
      _self.setData({
        items: data
      })
    });
  },
  formSubmit:function(e){
      let content = e.detail.value.summary;
      if(content==""){
        Dialog.alert({
          title: '提示',
          message: "请填写内容"
        });
        return;
      }
      console.log(this.data.userTag)
    user.updateIntroduce(content, this.data.userTag,function(data){
      var pages = getCurrentPages();
      if (pages.length > 1) {
        var prePage = pages[pages.length - 2];
        //关键在这里
        prePage.changeData("updateIntroduction");
        wx.navigateBack();
      }
    });
  },
  checkboxChange(e){
    _self.setData({
      userTag:e.detail.value
    })
  }

})